View Javadoc
1   /*
2    * GenericXmlResource.java
3    *
4    * Created on December 21, 2004, 11:09 AM
5    */
6   
7   package gov.noaa.eds.xapi.generic;
8   
9   import org.w3c.dom.Node;
10  import org.xmldb.api.base.ErrorCodes;
11  import org.xmldb.api.base.XMLDBException;
12  import org.xmldb.api.modules.XMLResource;
13  
14  /***
15   * Wraps a {@link DomHandler} implementation as an XMLResource
16   * @author tns
17   * @version $Id: GenericDomHandlerResource.java,v 1.2 2004/12/23 22:26:01 mrxtravis Exp $
18   */
19  public class GenericDomHandlerResource extends GenericResource implements XMLResource {
20      
21      private static String resourceType = "XMLResource";
22      /***
23       * Holds value of property domHandler.
24       */
25      private DomHandler domHandler;
26      
27      
28      /*** Creates a new instance of GenericXmlResource */
29      public GenericDomHandlerResource() {
30      }
31      
32      /*** Returns 'XMLResource'
33       *@return "XMLResource"
34       */
35      public String getResourceType(){
36          return this.resourceType;
37      }
38      
39      
40      /*** Getter for property domHandler.
41       * @return Value of property domHandler.
42       */
43      public DomHandler getDomHandler() {
44          
45          return this.domHandler;
46      }
47      
48      /***
49       * Setter for property domHandler.
50       * @param domHandler New value of property domHandler.
51       */
52      public void setDomHandler(DomHandler domHandler) {
53          
54          this.domHandler = domHandler;
55      }
56      
57      /*** Throws UnsupportedOperationException
58       *@throws UnsupportedOperationException
59       *@todo implement this getSAXFeature method
60       */
61      public boolean getSAXFeature(String str) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException {
62          throw new UnsupportedOperationException();
63      }
64      
65      /***Modifies this resource.  Depends on {@link DomHandler#setResourceAsNode}
66       *of the DomHandler implementation
67       *@param node The node to set this resource to reflect
68       *@throws XMLDBException If there is a Vendor error
69       */
70      public void setContentAsDOM(Node node) throws XMLDBException {
71          try {
72              this.domHandler.setResourceAsNode(node);
73          } catch (DomHandlerException e){
74              throw new XMLDBException(ErrorCodes.VENDOR_ERROR,e);
75          }
76      }
77      
78      /*** Does nothing
79       *@todo Implement this method
80       */
81      public void getContentAsSAX(org.xml.sax.ContentHandler contentHandler) throws XMLDBException {
82          throw new XMLDBException(ErrorCodes.NOT_IMPLEMENTED);
83      }
84      
85      /***throws unsupportedOperationException
86       *@todo Implement this method
87       */
88      public void setSAXFeature(String str, boolean param) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException {
89          throw new UnsupportedOperationException();
90      }
91      
92      /***throws NOT Implemented
93       *@todo Implement this method
94       */
95      public org.xml.sax.ContentHandler setContentAsSAX() throws org.xmldb.api.base.XMLDBException {
96          throw new XMLDBException(ErrorCodes.NOT_IMPLEMENTED);
97      }
98      
99      /***Returns the id of this resource
100      *@return The id of this resource
101      */
102     public String getDocumentId() throws XMLDBException {
103         return this.getId();
104     }
105     
106     /***Returns this resource as a DOM node
107      *@return The node representing the contents of this resource
108      */
109     public Node getContentAsDOM() throws XMLDBException {
110         try {
111             return this.domHandler.getResourceAsDocument();
112         } catch (DomHandlerException e){
113             throw new XMLDBException(ErrorCodes.VENDOR_ERROR,e);
114         }
115     }
116     
117     /***Accepts a DomHandler, otherwise throws an exception */
118     public void setContent(Object obj) throws XMLDBException {
119         if (obj instanceof DomHandler){
120             this.domHandler = (DomHandler) obj;
121         } else {
122             throw new XMLDBException(ErrorCodes.WRONG_CONTENT_TYPE);
123         }
124     }
125     
126     /***Returns the domHandler instance this resource is wrapping*/
127     public Object getContent() {
128         return this.domHandler;
129     }
130     
131 }